package org.study.seataxa.order.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.study.seataxa.order.service.OrderService;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2024年01月25日
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/order")
public class OrderController {
    private final OrderService orderService;

    /**
     * 下单：插入订单表、扣减库存
     */
    @RequestMapping("/placeOrder/commit")
    public Boolean placeOrderCommit() {
        orderService.placeOrder("1", "product-1", 1, false);
        return true;
    }

    /**
     * 下单：插入订单表、扣减库存，模拟回滚
     */
    @RequestMapping("/placeOrder/rollback1")
    public Boolean placeOrderRollback1() {
        orderService.placeOrder("1", "product-2", 1, false);
        return true;
    }

    /**
     * 下单：插入订单表、扣减库存，模拟回滚
     */
    @RequestMapping("/placeOrder/rollback2")
    public Boolean placeOrderRollback2() {
        orderService.placeOrder("1", "product-1", 1, true);
        return true;
    }
}
